package main

import (
	"fmt"
	"math"
	"unsafe"
)

// const 来定义枚举类型
//const (
//	BEIJING  = 0
//	SHANGHAI = 1
//	SHENZHEN = 2
//)

const (
	// BEIJING 可以在 const() 中添加一个关键字 iota，每行的iota都会累加 1，第一行的 iota 默认是 0
	BEIJING = 10 * iota
	SHANGHAI
	SHENZHEN
)

func main() {
	fmt.Println("-- 常量 --")
	//常量（只读属性）
	const length int = 37
	//length 常量是不允许被修改的
	fmt.Println("length = ", length)

	fmt.Println("BEIJING = ", BEIJING)
	fmt.Println("SHANGHAI = ", SHANGHAI)
	fmt.Println("SHENZHEN = ", SHENZHEN)

	Integer()
	fmt.Println("-----------------------------------")
	unsignedInteger()

	fmt.Println("-------浮点数------")
	showFloat()
	//showFloat(3.1111)
	fmt.Println("------字符-----")
	showChar()
	fmt.Println()
	sizeOfChar()
	var long rune = '龙'
	fmt.Printf("long = %c\t ", long)
	fmt.Printf("long 占用 %d 个字节\n", unsafe.Sizeof(long))

	fmt.Println("字符串")
	siteChan()
	ddSting()

	fmt.Println("布尔类型")
	showBool()

	fmt.Println("复数型")
	showComplex()
}

func showComplex() {
	//内置的complex 函数用于构建复数
	var x complex64 = complex(1, 2)
	var y complex128 = complex(3, 4)
	var z complex128 = complex(5, 6)
	fmt.Println("x = ", x)
	fmt.Println("y = ", y)
	fmt.Println("z = ", z)

	//内建的real 和 imag 函数分别返回复数的实部和虚部
	fmt.Println("real(x) = ", real(x))
	fmt.Println("imag(x) = ", imag(x))
	fmt.Println("y * z = ", y*z)

}

func showBool() {
	a := true
	b := false

	fmt.Println("a = ", a)
	fmt.Println("b = ", b)
	fmt.Println("true && false ", a && b)
	fmt.Println("true || false ", a || b)
}

func ddSting() {
	var s1 string
	s1 = `
	2025年的目标：16000
	技术练习：Go
	达到什么水平：微服务入门
	最终水平：微服务架构师
		`
	fmt.Println(s1)
}

func siteChan() {
	var study string       // 定义名为 study的字符串类型变量
	study = "《Go语言入门》" // 将变量赋值
	//以自动推断方式初始化
	study2 := "Go语言微服务架构师"
	fmt.Println(study, study2)
}

func sizeOfChar() {
	var x byte = 65
	fmt.Printf("x = %c\n", x)
	fmt.Printf("x 占用 %d 个字节\n", unsafe.Sizeof(x))

	var y rune = 'A'
	fmt.Printf("y = %c\n", y)
	fmt.Printf("y 占用 %d 个字节\n", unsafe.Sizeof(y))
}

func showChar() {
	var x byte = 65
	var y uint = 65
	fmt.Printf("x = %c \n", x)
	fmt.Printf("y = %c \n", y)
}

func showFloat() {
	var num1 float32 = math.MaxFloat32
	var num2 float64 = math.MaxFloat64
	fmt.Printf("num1 的类型是：%T,  num1是：%g \n", num1, num1)
	fmt.Printf("num2 的类型是：%T,  num2是：%g \n", num2, num2)
}

// 无符号类型
func unsignedInteger() {
	var num8 uint8 = 128
	var num16 uint16 = 32768
	var num32 uint32 = math.MaxUint32
	var num64 uint64 = math.MaxUint64
	var num uint = math.MaxUint

	fmt.Printf("num8的类型是：%T， num8的大小 = %d ， num8是： %d\n",
		num8, unsafe.Sizeof(num8), num8)
	fmt.Printf("num16的类型是：%T， num16的大小 = %d ， num16是： %d\n",
		num16, unsafe.Sizeof(num16), num16)
	fmt.Printf("num32的类型是：%T， num32的大小 = %d ， num32是： %d\n",
		num32, unsafe.Sizeof(num32), num32)
	fmt.Printf("num64的类型是：%T， num64的大小 = %d ， num64是： %d\n",
		num64, unsafe.Sizeof(num64), num64)
	fmt.Printf("num的类型是：%T， num的大小 = %d ， num是： %d\n",
		num, unsafe.Sizeof(num), num)
}

// Integer 有符号整形
func Integer() {
	var num8 int8 = 127
	var num16 int16 = 32767
	var num32 int32 = math.MaxInt32
	var num64 int64 = math.MaxInt64
	var num int = math.MaxInt

	fmt.Printf("num8的类型是：%T, num8的大小：%d num8是：%d \n",
		num8, unsafe.Sizeof(num8), num8)
	fmt.Printf("num16的类型是：%T, num16的大小：%d num16是：%d \n",
		num16, unsafe.Sizeof(num16), num16)
	fmt.Printf("num32的类型是：%T, num32的大小：%d num32是：%d \n",
		num32, unsafe.Sizeof(num32), num32)
	fmt.Printf("num64的类型是：%T, num64的大小：%d num64是：%d \n",
		num64, unsafe.Sizeof(num64), num64)
	fmt.Printf("num的类型是：%T, num的大小：%d num是：%d \n",
		num, unsafe.Sizeof(num), num)

}
